package com.school.edupoint.config;

import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

@Service
public class MessageProducer {

    private final RabbitTemplate rabbitTemplate;
    private final String queueName;

    // 使用构造器注入
    public MessageProducer(
            RabbitTemplate rabbitTemplate,
            @Value("${rabbitmq.queue.name}") String queueName
    ) {
        this.rabbitTemplate = rabbitTemplate;
        this.queueName = queueName;
    }

    public void sendMessage(Object message) {
        // 使用正确的发送方式
        rabbitTemplate.convertAndSend(queueName, message);
        System.out.println("Sent message to " + queueName + ": " + message);
    }
}